package org.ala.tree.lsm.sstable.block;

import java.nio.ByteBuffer;

/**
 * 尾巴块
 * <p>	定长16字节
 * <p>	索引段起始地址，索引段长度
 * <p>	元数据块索引地址，元数据块长度
 * 
 * @author ala
 * @date 2025年5月28日
 */
public class TailBlock {
	public static final int LEN = 16;
	
	
	/**
	 * 	索引段起始地址
	 */
	protected int indexOffset;
	/**
	 * 	索引段长度
	 */
	protected int indexLen;
	/**
	 * 	元数据块起始地址
	 */
	protected int metaOffset;
	/**
	 * 	元数据块长度
	 */
	protected int metaLen;
	
	
	public TailBlock(int indexOffset, int indexLen, int metaOffset, int metaLen) {
		super();
		this.indexOffset = indexOffset;
		this.indexLen = indexLen;
		this.metaOffset = metaOffset;
		this.metaLen = metaLen;
	}


	public ByteBuffer encode() {
		ByteBuffer buffer = ByteBuffer.allocateDirect(LEN);
		buffer.putInt(indexOffset);
		buffer.putInt(indexLen);
		buffer.putInt(metaOffset);
		buffer.putInt(metaLen);
		buffer.flip();
		return buffer;
	}
	public static TailBlock decode(ByteBuffer buf) {
		return new TailBlock(buf.getInt(), buf.getInt(), buf.getInt(), buf.getInt());
	}


	public int getIndexOffset() {
		return indexOffset;
	}


	public void setIndexOffset(int indexOffset) {
		this.indexOffset = indexOffset;
	}


	public int getIndexLen() {
		return indexLen;
	}


	public void setIndexLen(int indexLen) {
		this.indexLen = indexLen;
	}


	public int getMetaOffset() {
		return metaOffset;
	}


	public void setMetaOffset(int metaOffset) {
		this.metaOffset = metaOffset;
	}


	public int getMetaLen() {
		return metaLen;
	}


	public void setMetaLen(int metaLen) {
		this.metaLen = metaLen;
	}
	
	
}
